﻿var winState = "0";

Ext.onReady(function () {
    yeardata = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetYearTime'),
        root: 'ResponseObject',
        fields: ['yearid', 'yeartext'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    yeardata.load();
    //数据列表
    var lmsstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('ProductReportView', 'GetRentalPrice'),
        root: 'ResponseObject',
        fields: ['队组名称', '定额金额', '租赁金额'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });

    function NumFormat(s, m) {
        if (s < 0) m.css = 'redNum';
        //if (s == 0) return '';
        return Ext.util.Format.number(s, '0.00');
    }
    var lmsdatagrid = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        columns: [
           { header: '队组名称', width: 100, dataIndex: '队组名称', sortable: true },
           { header: '定额金额', width: 100, dataIndex: '定额金额', sortable: true },
           { header: '租赁金额', width: 100, dataIndex: '租赁金额', sortable: true }
        ],
        store: lmsstore,
        listeners: {
            rowclick: function (g, r) {

            },
            celldblclick: function (grid, rindex) {
                if (grid.getSelectionModel().selections.items[0].json.队组名称 != '合计') {
                    window.open('../ChildReport/Rental_child.aspx?dz=' + escape(grid.getSelectionModel().selections.items[0].json.队组名称));
                }
            }
        }
    });


    //数据列表
    var lmsstore1 = new Ext.data.JsonStore({
        url: Ext.getClassUrl('ProductReportView', 'GetRentalCount'),
        root: 'ResponseObject',
        fields: ['设备名称', '租用数量'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    var lmsdatagrid1 = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        columns: [
           { id: '设备名称', header: '设备名称', width: 100, dataIndex: '设备名称', sortable: true },
           { header: '租用数量', width: 100, dataIndex: '租用数量', sortable: true }
        ],
        store: lmsstore1,
        listeners: {
            rowclick: function (g, r) {

            },
            celldblclick: function (grid, rindex) {
                if (grid.getSelectionModel().selections.items[0].json.设备名称 != '合计') {
                    window.open('../ChildReport/Rental_count.aspx?equipment=' + escape(grid.getSelectionModel().selections.items[0].json.设备名称));
                }
            }
        }
    });
    //布局
    new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            layout: 'border',
            border: false,
            title: '设备租赁分析报表',
            iconCls: 'ReportTitle-icon',
            tbar: ['日期：', { xtype: 'combo', width: 100, id: 'year',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: yeardata,
                valueField: 'yearid',
                displayField: 'yeartext'

            }, '年', { xtype: 'combo', width: 70, id: 'month',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: [
                            'monthid',
                            'monthtext'
                        ],
                    data: [['01', '01'], ['02', '02'], ['03', '03'], ['04', '04'], ['05', '05'], ['06', '06'], ['07', '07'], ['08', '08'], ['09', '09'], ['10', '10'], ['11', '11'], ['12', '12']]
                }),
                valueField: 'monthid',
                displayField: 'monthtext'
            }, '月', { xtype: 'button', text: '查询', iconCls: 'search-icon', handler: function () {
                lmsstore.load();
                lmsstore1.load();
            }
            },'->', { xtype: 'button', text: '返回', height: 20, width: 50, iconCls: 'page-back-icon', handler: function () {
                window.history.back(-1);
            }
            }],
            items: [{
                region: 'west',
                title: '租用资金分析',
                iconCls: 'DataList-icon',
                collapsible: true,
                width: 700,
                split: true,
                id: 'DataList',
                border: false,
                layout: 'border',
                style: 'padding:2px',
                items: [{
                    region: 'center',
                    style: 'padding-top:2px;padding-right:2px;padding-bottom:2px',
                    layout: 'fit',
                    items: lmsdatagrid
                }, {
                    region: 'south',
                    style: 'padding:2px;',
                    height: 300,
                    title: '租赁资金分析图',
                    collapsible: true,
                    split: true,
                    iconCls: 'Piechart-icon',
                    items: [{
                        xtype: 'columnchart',
                        store: lmsstore,
                        chartStyle: {
                            padding: 10,
                            animationEnabled: true,
                            legend: {
                                display: 'right',
                                padding: 2,
                                font: {
                                    family: 'Tahoma',
                                    size: 11
                                }
                            },
                            font: {
                                name: 'Tahoma',
                                color: 0x444444,
                                size: 11
                            },
                            dataTip: {
                                padding: 5,
                                border: {
                                    color: 0x99bbe8,
                                    size: 1
                                },
                                background: {
                                    color: 0xDAE7F6,
                                    alpha: .9
                                }
                            },
                            xAxis: {
                                color: 0x69aBc8,
                                majorTicks: { color: 0x69aBc8, length: 4 },
                                minorTicks: { color: 0x69aBc8, length: 2 },
                                majorGridLines: { size: 1, color: 0xeeeeee },
                                labelRotation: -90
                            },
                            yAxis: {
                                zeroGridLine:
                        	    {
                        	        size: 2,
                        	        color: 0xff0000
                        	    },
                                color: 0x69aBc8,
                                majorTicks: { color: 0x69aBc8, length: 4 },
                                minorTicks: { color: 0x69aBc8, length: 2 },
                                majorGridLines: { size: 1, color: 0xdfe8f6 }
                            }
                        },
                        xField: '队组名称',
                        yField: '资金合计',
                        yAxis: new Ext.chart.NumericAxis({
                            displayName: '资金合计',
                            labelRenderer: Ext.util.Format.numberRenderer('0,0')
                        }),
                        series: [{
                            type: 'column',
                            displayName: '定额金额',
                            yField: '定额金额',
                            style: {
                                color: 0x8DB6CD
                            }
                        }, {
                            type: 'column',
                            displayName: '租赁金额',
                            yField: '租赁金额',
                            style: {
                                color: 0x8B8B00
                            }
                        }]
                    }]
                }]
            }, {
                region: 'center',
                split: true,
                layout: 'border',
                split: true,
                border: false,
                id: 'ImgCount',
                items: [{
                    region: 'center',
                    title: '租用数量分析',
                    iconCls: 'ImgDataList-icon',
                    id: 'ImgDataList',
                    style: 'padding-top:2px;padding-right:2px;padding-bottom:2px',
                    layout: 'fit',
                    items: lmsdatagrid1
                }, {
                    id: 'piePanel',
                    region: 'south',
                    title: '租赁数量分析图',
                    collapsible: true,
                    split: true,
                    height: 300,
                    iconCls: 'Piechart-icon',
                    style: 'padding:2px;',
                    items: [{
                        xtype: 'columnchart',
                        store: lmsstore1,
                        chartStyle: {
                            padding: 10,
                            animationEnabled: true,
                            legend: {
                                display: 'right',
                                padding: 2,
                                font: {
                                    family: 'Tahoma',
                                    size: 11
                                }
                            },
                            font: {
                                name: 'Tahoma',
                                color: 0x444444,
                                size: 11
                            },
                            dataTip: {
                                padding: 5,
                                border: {
                                    color: 0x99bbe8,
                                    size: 1
                                },
                                background: {
                                    color: 0xDAE7F6,
                                    alpha: .9
                                }
                            },
                            xAxis: {
                                color: 0x69aBc8,
                                majorTicks: { color: 0x69aBc8, length: 4 },
                                minorTicks: { color: 0x69aBc8, length: 2 },
                                majorGridLines: { size: 1, color: 0xeeeeee },
                                labelRotation: -90
                            },
                            yAxis: {
                                zeroGridLine:
                        	    {
                        	        size: 2,
                        	        color: 0xff0000
                        	    },
                                color: 0x69aBc8,
                                majorTicks: { color: 0x69aBc8, length: 4 },
                                minorTicks: { color: 0x69aBc8, length: 2 },
                                majorGridLines: { size: 1, color: 0xdfe8f6 }
                            }
                        },
                        xField: '设备名称',
                        yField: '数量合计',
                        yAxis: new Ext.chart.NumericAxis({
                            displayName: '数量合计',
                            labelRenderer: Ext.util.Format.numberRenderer('0,0')
                        }),
                        series: [{
                            type: 'column',
                            displayName: '租用数量',
                            yField: '租用数量',
                            style: {
                                color: 0x8DB6CD
                            }
                        }]
                    }]
                }]
            }]
        }],
        listeners: {
            render: function () {
                Ext.getCmp("year").setValue(YearT);
                Ext.getCmp("month").setValue(MonthT);

                lmsstore.reload();
                lmsstore1.reload();
                //lmsstore1.reload.defer(1500, lmsstore1);
            }
        }
    })


});


